
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gpsserver;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author DELL
 */
public class Main {

    private static int PORT = 5222;

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = null;
        Socket clientSocket = null;

        try {
            serverSocket = new ServerSocket(PORT);
            System.out.println("Server initiated on port: " + PORT + ".");
        } catch (IOException e) {
            System.err.println("Could not listen on port: " + PORT + ".");
            System.exit(1);
        }

        while (true) {
            try {
                clientSocket = serverSocket.accept();
                System.out.println("new client accepted. IP = " + clientSocket.getInetAddress());
                new ServerThread(clientSocket).start();
            } catch (IOException e) {
                System.err.println("Accept failed.");
                System.exit(1);
            }
        }
    }

    private void state(String mensaje) {
        System.out.println(mensaje);
    }
}